<?php

/**
 * cambiocontra actions.
 *
 * @package    SistemaWebUnlSenescyt
 * @subpackage cambiocontra
 * @author     JFernando
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class cambiocontraActions extends sfActions {

    public function executeIndex(sfWebRequest $request) {
        

        $this->sfguardusers = Doctrine_Core::getTable('sfguarduser')
                ->createQuery('a')
                ->execute();
        $this->form = new sfGuardUserForm3();
        if ($request->isMethod('post')) {
            $this->form->bind($request->getParameter('sf_guard_user'));
            if ($this->form->isValid()) {
                $this->form->save();
                $this->getUser()->signIn($this->form->getObject());
                $this->redirect('inicio/index');
            }
        }
    }

    public function executeShow(sfWebRequest $request) {
        $this->sfguarduser = Doctrine_Core::getTable('sfguarduser')->find(array($request->getParameter('id')));
        $this->forward404Unless($this->sfguarduser);
    }

    public function executeNew(sfWebRequest $request) {
        $this->form = new sfGuardUserForm4();
    }

    public function executeCreate(sfWebRequest $request) {
        $this->forward404Unless($request->isMethod(sfRequest::POST));

        $this->form = new sfGuardUserForm4();

        $this->processForm($request, $this->form);

        $this->setTemplate('new');
    }

    public function executeEdit(sfWebRequest $request) {
        $this->forward404Unless($sfguarduser = Doctrine_Core::getTable('sfguarduser')->find(array($request->getParameter('id'))), sprintf('Object sfguarduser does not exist (%s).', $request->getParameter('id')));
        $this->form = new sfGuardUserForm4($sfguarduser);
    }

    public function executeUpdate(sfWebRequest $request) {
        $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
        $this->forward404Unless($sfguarduser = Doctrine_Core::getTable('sfguarduser')->find(array($request->getParameter('id'))), sprintf('Object sfguarduser does not exist (%s).', $request->getParameter('id')));
        $this->form = new sfGuardUserForm4($sfguarduser);
        $this->processForm($request, $this->form);
        $this->setTemplate('edit');
    }

    public function executeDelete(sfWebRequest $request) {
        $request->checkCSRFProtection();

        $this->forward404Unless($sfguarduser = Doctrine_Core::getTable('sfguarduser')->find(array($request->getParameter('id'))), sprintf('Object sfguarduser does not exist (%s).', $request->getParameter('id')));
        $sfguarduser->delete();

        $this->redirect('cambiocontra/index');
    }

    protected function processForm(sfWebRequest $request, sfForm $form) {
        $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
        if ($form->isValid()) {
            $sfguarduser = $form->save();
            $this->redirect('@sf_guard_signin');
            
        }
        
    }

}
